package com.retail.shopping.server.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import com.retail.shopping.common.domain.response.CartListResponse;
import com.retail.shopping.server.service.impl.ShopCartBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.retail.shopping.server.service.IShoppingCartMiddenService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;

/**
 * 购物车列表Controller
 * 
 * @author retail
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/shoppingCartList")
public class ShoppingCartMiddenController extends BaseController {
    @Autowired
    private IShoppingCartMiddenService shoppingCartMiddenService;
    @Autowired
    private ShopCartBatchService shopCartBatchService;

    /**
     * 查询购物车列表列表
     * 切换
     */
    //@RequiresPermissions("shopping:shoppingCartList:list")
    @GetMapping("/shoppingCartMergeList/{userId}")
    public Callable<Map<String, List<Map<String, Object>>>> shoppingCartMergeList(@PathVariable("userId") Integer userId) {
        return new Callable<Map<String, List<Map<String, Object>>>> () {
            @Override
            public Map<String, List<Map<String, Object>>> call() throws Exception {
                return shopCartBatchService.selectShoppingCartMergeMiddenList (userId);
            }
        };
    }


    @GetMapping("/shoppingCartList")
    public Result<List<CartListResponse>> list(@RequestParam("userId") Integer userId) {
        Result<List<CartListResponse>> result = shoppingCartMiddenService.selectShoppingCartMiddenList (userId);
        return result;
    }

    @PostMapping("/deleteCartMiddenBySkuUser")
    public Result deleteCartMiddenBySkuUser(@RequestParam("userId") Integer userId, @RequestParam("str") String str) {
        shoppingCartMiddenService.deleteCartMiddenBySkuUser (userId, str);

        return Result.success ("");

    }


}